import java.util.LinkedList;
import java.util.Queue;

public class TreeQueue {
    public class TreeNode{
        public char val;
        public TreeNode left;
        public TreeNode right;
        public void TreeNode(char val) {
            this.val = val;
        }
    }
    public boolean IsCompleteBinaryTree(TreeNode root) {
        if (root == null) {
            return true;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()) {
            TreeNode cur = queue.poll();
            if(cur != null) {
                queue.offer(cur.left);
                queue.offer(cur.right);
            } else {
                break;//结束之后 遍历队列剩下的所有元素是不是都是null
            }
        }
        // 遍历队列剩下的所有元素 是不是都是null
        while (!queue.isEmpty()) {
            TreeNode cur = queue.poll();
            if(cur != null) {
                return false;
            }
        }
        return true;
    }
}
